<?php

abstract class Vnf_Controller_Action extends Zend_Controller_Action
{

    //protected $layoutPath = BASE_DIR . '/layouts/user/';
//    protected $layout = 'index';

    /**
     * Set layout
     *
     * @param $layout
     * @param $layoutPath
     */
    public function setLayout($layout = 'index', $layoutPath = null) {

        $layoutPath = $layoutPath == null? BASE_DIR . '/layouts/' . CURR_APP_PATH . '/':$layoutPath;
        Zend_Layout::startMvc(array(
            'layoutPath' => $layoutPath,
            'layout' => $layout
        ));
    }

    /**
     * Get param from URL or get from pre URL (use in login form)
     *
     * @param $lparamName
     * @param $defaultValue
     */
    public function getParam($paramName, $defaultValue) {
        $param = $this->_request->getParam($paramName);
        if (!$param) { // has no value
            // get value from login form
            $params = Zend_Json::decode($this->_request->getParam("lastparams", "{}"));
            
            // get from last page
            $param = @$params[$paramName];
            
            // get default value if has not value transfer
            $param = $param?$param:$defaultValue;
        }
        
        return $param;
    }
}